﻿using System.ComponentModel.DataAnnotations;
using AutoMapper;

namespace CashFlow.Entities.Models
{
	public class BillListModel
	{
		static BillListModel()
		{
			Mapper.CreateMap<Bill, BillListModel>()
				.ForMember(dest => dest.Amount, opt => opt.MapFrom(src =>
					src.Amount < 0 ? -1 * src.Amount : src.Amount))
				.ForMember(dest => dest.Recurrence, opt => opt.MapFrom(src =>
					src.Recurrence.Name));
		}

		public string Id { get; set; }
		[Display(Name = "Description")]
		public string Details { get; set; }
		[Display(Name = "Amount")]
		public string Amount { get; set; }
		[Display(Name = "Recurrence")]
		public string Recurrence { get; set; }
		[Display(Name = "Details")]
		public string PayeeName { get; set; }

		public static explicit operator BillListModel(Bill entity)
		{
			return Mapper.Map<Bill, BillListModel>(entity);
		}
	}
}
